
<div class="layui-fluid" style="padding: 15px">
    <div class="layui-card" style="padding-top: 10px">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" method="post" action="">
                    <div class="layui-row">
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">托运单号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <input type="text" name="checkenumber" lay-verify="required" autocomplete="off"
                                               placeholder="请输入" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">外包单号：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <input type="text" name="outsourcingnumber" lay-verify="title" autocomplete="off"
                                               placeholder="请输入" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo grid-demo-bg1">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">外包公司：</label>
                                    <div class="layui-input-block" style="width:180px;">
                                        <select name="outsourcingcompany" id="outsourcingcompany"  lay-search="">
                                            <option value=""></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs3">
                            <div class="grid-demo">

                                <div class="layui-form-item">
                                    <label class="layui-form-label">转包日期：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="subcontractingdate" id="subcontractingdate" lay-verify="date1"
                                               placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs12" style="height:30px">
                            <div class="grid-demo">
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit
                                            lay-filter="formDemo">外包查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-row">
                    <table class="layui-hide" id="otherlist" lay-filter="otherlist"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="updateother">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delectother">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table = layui.table;
        var $ = layui.jquery;

        //日期初始化
        form.render();
        var tableIns=table.render({
            elem: '#otherlist'
            ,url:'../../queryother'
            ,title: '其它外包数据表'
            ,height:420
            ,cols: [[
                {type:'checkbox'}
                ,{field:'checkenumber', title:'原托运单号', width:150, sort: true}
                ,{field:'outsourcingnumber', title:'外包单号', width:150}
                ,{field:'outsourcingcompany', title:'外包公司', width:150}
                ,{field:'outsourcephone', title:'外包电话', width:150}
                ,{field:'subcontractingdate', title:'转包日期', width:150}
                ,{field:'outsourcedfreight', title:'外包运费', width:150}
                ,{field:'outsourcingtype', title:'外包类型', width:150}
                ,{field:'consigners', title:'发货人', width:150}
                ,{field:'shippingphone', title:'发货电话', width:150}
                ,{field:'shippersbackupphone', title:'备用电话', width:170}
                ,{field:'shippingunits', title:'发货单位', width:150}
                ,{field:'shippingaddress', title:'发货地址', width:150}
                ,{field:'consignees', title:'收货人', width:150}
                ,{field:'receivingphone', title:'收货电话', width:150}
                ,{field:'consigneesbackupphone', title:'备用电话', width:150}
                ,{field:'receivingunit', title:'收货单位', width:150}
                ,{field:'receiptaddress', title:'收货地址', width:150}
                ,{field:'storagesite', title:'入库站点', width:150}
                ,{field:'deliverytime', title:'派送时间', width:150}
                ,{field:'operateyuan', title:'操作员', width:150}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });
        //监听行工具事件
        table.on('tool(otherlist)',function (obj) {
            switch (obj.event) {
                case 'updateother':
                    var waybillid=obj.data.checkenumber;
                    updateotherDate(waybillid);
                    break;
                case 'delectother':
                    var otherid=obj.data.outsourcingnumber;
                    delectotherDate(otherid);
                default:
                    break;
            }
        })

        /*表单提交*/
        form.on('submit(formDemo)', function(data){
            tableIns.reload({
                type:'post'
                ,url:'../../conditionalqueryOther',
                where: {
                    //设定异步数据接口的额外参数，任意设
                    checkenumber:data.field.checkenumber
                    ,outsourcingnumber:data.field.outsourcingnumber
                    ,outsourcingcompany:data.field.outsourcingcompany
                    ,subcontractingdate:data.field.subcontractingdate
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });

        /*删除其他外包*/
        function delectotherDate(otherid) {
            layui.use(['layer','table','jquery'], function(){
                var layer = layui.layer;
                var table = layui.table;
                var $ = layui.jquery;
                layer.open({
                    content: '测试回调',
                    //大小
                    area:['300px', '180px'],
                    btn: ['确定','取消'],
                    content: '确定要提交删除?',
                    yes: function(index,kskks){
                        $.ajax({
                            url:'../../delectother',
                            type:'post',
                            dataType:'text',
                            data:{
                                orderno:otherid
                            },
                            success:function(data){

                                //表刷新方法
                                alert(data);
                                reloads();
                            }
                        });
                        layer.close(index);
                    }

                });
            });
        }

        /*修改其它外包信息*/
        function updateotherDate(waybillid) {
            layui.use(['table','jquery','form'], function(){
                var form = layui.form;
                var table = layui.table;
                var $ = layui.jquery;
                $.ajax({
                    url : '../../getOtheroutsourcingByid',
                    method : 'post',
                    data :{
                        outsourcingid:waybillid
                    } ,
                    dataType:"json",
                    success:function(data) {
                        updateotherpopup();
                        setTimeout(function () {
                            //jquery获取内嵌框架对象
                            var other = $("#other").contents();
                            other.find("#consigners").val(data.consigners);
                            other.find("#shippingphone").val(data.shippingphone);
                            other.find("#shippingunits").val(data.shippingunits);
                            other.find("#shippingaddress").val(data.shippingaddress);
                            other.find("#consignees").val(data.consignees);
                            other.find("#receivingphone").val(data.receivingphone);
                            other.find("#receivingunit").val(data.receivingunit);
                            other.find("#receiptaddress").val(data.receiptaddress);
                            other.find("#checkenumber").val(data.checkenumber);
                            other.find("#outsourcingnumber").val(data.outsourcingnumber);
                            other.find("#outsourcingcompany").val(data.outsourcingcompany);
                            other.find("#outsourcephone").val(data.outsourcephone);
                            other.find("#subcontractingdate").val(data.subcontractingdate);
                            other.find("#outsourcedfreight").val(data.outsourcedfreight);
                            other.find("#outsourcingtype").val(data.outsourcingtype);
                        }, 500);
                    }
                });
            });
        }

        /*弹出层其他外包修改*/
        function updateotherpopup(){
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    skin:'layui-layer-molv',//皮肤
                    content: '测试回调',
                    //大小
                    area:['90%', '650px'],
                    btn: [],
                    content: '<iframe src="otherinformation.html" id="other" width="100%" height="100%" frameborder="0"/>',
                    closeBtn: 2, //关闭按钮样式默认1
                    anim:4 //设置关闭动画
                });
            });
        }

        /* 表刷新方法 */
        function reloads(){
            layui.use('layer', function(){
                var table = layui.table;
                table.reload("otherlist");
            });
        }
    });
</script>